package com.jarchie.greendao;

import com.jarchie.greendao.gen.DaoMaster;
import com.jarchie.greendao.gen.DaoSession;

/**
 * Created by Jarchie on 2017\10\30 0030.
 * GreenDao管理类
 */

public class GreenDaoManager {
    private static GreenDaoManager mInstance;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;

    private GreenDaoManager(){
//        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(MyApplication.getContext(), "test-db", null);
//        DaoMaster mDaoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
        MySQLiteOpenHelper helper = new MySQLiteOpenHelper(MyApplication.getContext(),"test-db",null);
        mDaoMaster = new DaoMaster(helper.getWritableDatabase());
        mDaoSession = mDaoMaster.newSession();
    }

    public static GreenDaoManager getInstance(){
        if (mInstance == null){
            mInstance = new GreenDaoManager();
        }
        return mInstance;
    }

    public DaoMaster getMaster(){
        return mDaoMaster;
    }

    public DaoSession getDaoSession(){
        return mDaoSession;
    }

    public DaoSession getNewSession(){
        mDaoSession = mDaoMaster.newSession();
        return mDaoSession;
    }

}
